<?php

namespace Modules\Admin\Http\Controllers;

use \Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Admin\Http\Requests\AdminPostRequest;
use Modules\Admin\Http\Requests\CommonIdRequest;
use Modules\Admin\Services\AdminService;

class AdminController extends Controller
{
    protected $service = null;

    public function __construct()
    {
       $this->service = new AdminService();
    }
    /**
     * Display a listing of the resource.
     * @return JsonResponse
     */
    public function index(): JsonResponse
    {
       return $this->service->list();
    }



    /***
     * @param AdminPostRequest $request
     * @return JsonResponse
     * 注册
     */
    public function store(AdminPostRequest $request):JsonResponse
    {
        return $this->service->store($request->only([
            'username',
            'nickname',
            'password',
            'email'
        ]));
    }


    /**
     * Show the form for editing the specified resource.
     * @param int $id
     * @return JsonResponse
     *
     */
    public function edit(CommonIdRequest $request):JsonResponse
    {
        return $this->service->edit($request->get('id'));
    }

    /**
     * Update the specified resource in storage.
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     */
    public function update(AdminPostRequest $request)
    {

    }

    /**
     * Remove the specified resource from storage.
     * @param int $id
     * @return Renderable
     */
    public function destroy($id)
    {
        //
    }
}
